//
//  OrderDetailAddressTableViewCell.m
//  much
//
//  Created by Believer Just on 2019/1/11.
//  Copyright © 2019年 iOS. All rights reserved.
//

#import "OrderDetailAddressTableViewCell.h"

@interface OrderDetailAddressTableViewCell ()

@property (strong, nonatomic) UILabel * orderNumberLabel;
@property (strong, nonatomic) UILabel * orderStatusLabel;//订单状态
@property (strong, nonatomic) UILabel * nameLabel;
@property (strong, nonatomic) UILabel * phoneLabel;
@property (strong, nonatomic) UILabel * addressDetailLabel;
@property (nonatomic, strong) UIImageView *titleImageView;

@end

@implementation OrderDetailAddressTableViewCell

+ (instancetype)initTableView:(UITableView *)tableView {
    OrderDetailAddressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([OrderDetailAddressTableViewCell class])];
    if (!cell) {
        cell = [[OrderDetailAddressTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([OrderDetailAddressTableViewCell class])];
    }
    return cell;
}

- (void)setModel:(Orders *)model {
    _model = model;
    /**
    self.titleImageView.backgroundColor = [UIColor clearColor];
    self.orderStatusLabel.text = model.orderStateText;
    self.orderNumberLabel.text = [NSString stringWithFormat:@"订单号：%@", model.orderId];
    self.nameLabel.text = model.name;
    self.phoneLabel.text = model.phone;
    self.addressDetailLabel.text = model.address;
     */
}


#pragma mark - 懒加载
- (UILabel *)orderStatusLabel {
    if (!_orderStatusLabel) {
        _orderStatusLabel = [UILabel new];
        _orderStatusLabel.font = APPFONT(12);
        _orderStatusLabel.textColor = Color175030;
        [self.contentView addSubview:_orderStatusLabel];
        [_orderStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).with.offset(-18);
            make.height.mas_equalTo(@30);
        }];
    }
    return _orderStatusLabel;
}

- (UIImageView *)titleImageView {
    if (!_titleImageView) {
        _titleImageView = [UIImageView new];
        [_titleImageView setImage:[UIImage imageNamed:@"order_logistics_add"]];
        [self.contentView addSubview:_titleImageView];
        [_titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(18);
            make.height.mas_equalTo(@15);
            make.width.mas_equalTo(@15);
            make.centerY.equalTo(self.contentView.mas_centerY).multipliedBy(1.3);
        }];
    }
    return _titleImageView;
}

- (UILabel *)orderNumberLabel {
    if (!_orderNumberLabel) {
        _orderNumberLabel = [UILabel new];
        _orderNumberLabel.font = APPFONT(12);
        _orderNumberLabel.textColor = HEXCOLOR(0x353535);
        [self.contentView addSubview:_orderNumberLabel];
        [_orderNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(18);
            make.height.mas_equalTo(@30);
        }];
        
        UIButton *copyBtn = [[UIButton alloc] init];
        [copyBtn setTitle:@"复制" forState:UIControlStateNormal];
        [copyBtn setTitleColor:Color34 forState:UIControlStateNormal];
        copyBtn.titleLabel.font = APPFONT(10);
        [copyBtn xw_roundedCornerWithCornerRadii:CGSizeMake(2, 2) cornerColor:[UIColor whiteColor] corners:UIRectCornerAllCorners borderColor:Color140 borderWidth:0.5];
        [self.contentView addSubview:copyBtn];
        [copyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.orderNumberLabel.mas_right).with.offset(10);
            make.height.mas_equalTo(14);
            make.width.mas_equalTo(28);
            make.centerY.equalTo(self.orderNumberLabel);
        }];
        [copyBtn addTarget:self action:@selector(copyBtnAction) forControlEvents:UIControlEventTouchUpInside];
        
        UIView * line = [UIView new];
        line.backgroundColor = HEXCOLOR(0xE4E4E4);
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.orderNumberLabel);
            make.top.mas_equalTo(30);
            make.right.equalTo(self.contentView);
            make.height.mas_equalTo(@1);
        }];
    }
    return _orderNumberLabel;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.font = APPFONT(15);
        _nameLabel.textColor = HEXCOLOR(0x353535);
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleImageView.mas_right).with.offset(10);
            make.top.mas_equalTo(@39);
        }];
    }
    return _nameLabel;
}

- (UILabel *)phoneLabel {
    if (!_phoneLabel) {
        _phoneLabel = [UILabel new];
        _phoneLabel.font = APPFONT(15);
        _phoneLabel.textColor = HEXCOLOR(0x353535);
        [self.contentView addSubview:_phoneLabel];
        [_phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.nameLabel.mas_right).with.offset(10);
            make.centerY.equalTo(self.nameLabel);
        }];
    }
    return _phoneLabel;
}

- (UILabel *)addressDetailLabel {
    if (!_addressDetailLabel) {
        _addressDetailLabel = [UILabel new];
        _addressDetailLabel.font = APPFONT(12);
        _addressDetailLabel.numberOfLines = 2;
        _addressDetailLabel.textColor = HEXCOLOR(0x8a8a8a);
        [self.contentView addSubview:_addressDetailLabel];
        [_addressDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.nameLabel.mas_bottom).with.offset(5);
            make.height.mas_lessThanOrEqualTo(@26);
            make.left.equalTo(self.nameLabel);
            make.right.equalTo(self.contentView).with.offset(-18);
        }];
    }
    return _addressDetailLabel;
}

- (void)copyBtnAction {
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    if (self.model.orderId.hasValue) {
        pasteboard.string = self.model.orderId;
    }
    if (pasteboard.string == nil) {
        [SVProgressHUD showErrorWithStatus:@"复制失败"];
    } else {
        [SVProgressHUD showSuccessWithStatus:@"复制成功"];
    }
}

@end
